package com.csw.shuanfa.CodeImprove.Transaction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【编程式事务】
 */
@RestController
@RequestMapping("TransactionAuto")
public class PersonTransationAutoCommit {
    @Autowired
    private TransactionTemplate transactionTemplate;

    @RequestMapping("show")
    public void show(String name) {
        System.out.println("Thread.currentThread().getName() = " + Thread.currentThread().getName());
        System.out.println("======>show...");

        transactionTemplate.executeWithoutResult(status -> {//无返回值
            System.out.println(">>>>>>数据库操作");

            transactionTemplate.execute(status1 -> {//有返回值
                System.out.println(">>>>>>数据库操作");
                return null;
            });

        });
    }
//————————————————
//    版权声明：本文为CSDN博主「魔道不误砍柴功」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
//    原文链接：https://blog.csdn.net/qq_35971258/article/details/128620476
}
